import QtQuick 2.0
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import ConfigElementType 1.0
import "qrc:/qmlComponents/ConfigManager"
import "qrc:/qmlComponents/AxisModulePos"
import "qrc:/qmlComponents/VisionViewer"

Item{
    RowLayout{
        spacing: 30

        ColumnLayout{
            Layout.alignment: Qt.AlignTop

            SAxisModulePos{
                moduleName: "BWHBeltZ"
                posName: "UpPos"
            }
            SAxisModulePos{
                moduleName: "BWHBeltZ"
                posName: "DownPos"
            }
            SAxisModulePos{
                moduleName: "BWHTrackZ"
                posName: "UpPos"
            }
            SAxisModulePos{
                moduleName: "BWHTrackZ"
                posName: "DownPos"
            }
            SAxisModulePos{
                moduleName: "BWHTrackX"
                posName: "LoadTrayPos"
            }
            SAxisModulePos{
                moduleName: "BWHTrackX"
                posName: "UnloadTrayPos"
            }
        }

        ColumnLayout{
            Layout.alignment: Qt.AlignTop
            spacing: 40

            VisionLocationViewer{
                visionLocationName: "MoveBWHDLCameraLocation"
                calibrationName: "MoveBWHDLCameraCalibration"
            }

            RowLayout{
                spacing: 30

                ColumnLayout{
                    Layout.alignment: Qt.AlignTop
                    spacing: 25

                    GroupBox{
                        title: qsTr("BonderWorkHolderConfig")
                        ColumnLayout{
                            ConfigRow{
                                configModel: bwhConfig
                                configName: "beltRunDirection"
                                Component.onCompleted: {
                                    init(ConfigElementType.Other)
                                }
                            }
                            ConfigRow{
                                configModel: bwhConfig
                                configName: "getNewTrayTimeout"
                                Component.onCompleted: {
                                    init(ConfigElementType.Int)
                                }
                            }
                        }
                    }

                    ObjectEditor{
                        sectionName: "SensorTrayConveyerConfig"
                        configModel: stcConfig
                        Component.onCompleted: {
                            init()
                        }
                    }
                }

                ColumnLayout{
                    Layout.alignment: Qt.AlignTop
                    spacing: 25

                    RowLayout{
                        CheckBox{
                            id: ckbNeewShotGlue
                            text: qsTr("需要点胶")
                        }
                        Button{
                            text: qsTr("GetNewTray")
                            onClicked: {
                                tem.runSingleCmd(bonderWorkHolder, "manuallyGetNewTray", [ckbNeewShotGlue.checked])
                            }
                        }
                        Button{
                            text: qsTr("CancelGetTray")
                            onClicked: {
                                bonderWorkHolder.cancelManuallyGetNewTray()
                            }
                        }
                    }

                    Button{
                        text: qsTr("PushOutTray")
                        onClicked: {
                            tem.runSingleCmd(bonderWorkHolder, "manuallyPushOutTray")
                        }
                    }

                    Button{
                        text: qsTr("DownBeltZAndTrackZ")
                        onClicked: {
                            tem.runSingleCmd(bonderWorkHolder, "downBeltZAndTrackZ")
                        }
                    }

                    GroupBox{
                        title: qsTr("LoadUnloadTrayLoopTest")
                        ColumnLayout{
                            RowLayout{
                                Label{
                                    text: qsTr("Times:")
                                }
                                TextField{
                                    id: txtTimes
                                    text: "10"
                                    selectByMouse : true
                                    validator: IntValidator{}
                                }
                            }
                            RowLayout{
                                Button{
                                    text: qsTr("Start")
                                    onClicked: {
                                        tem.runSingleCmd(bonderWorkHolder, "startLoadUnloadTrayLoopTest", [txtTimes.text])
                                    }
                                }
                                Button{
                                    text: qsTr("Stop")
                                    onClicked: {
                                        bonderWorkHolder.stopLoadUnloadTrayLoopTest()
                                    }
                                    ToolTip{
                                        text: qsTr("You have to click 'Reset' button after loop test stopped.")
                                        visible: parent.hovered
                                    }
                                }
                                Button{
                                    text: qsTr("Reset")
                                    onClicked: {
                                        bonderWorkHolder.resetLoadUnloadTrayLoopTest()
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
